package com.fzg.common.enums;

import com.fzg.common.exception.BusinessException;
import lombok.Data;

/**
 * @author: 范占国
 * @description: 接口统一返回类
 */
@Data
public class ResponseWrapper {

    /**
     * 返回码
     */
    private Integer code;
    /**
     * 提示信息
     */
    private String message;
    /**
     * 返回数据
     */
    private Object data;

    /**
     * 自定义返回结果
     * 建议使用统一的返回结果，特殊情况可以使用此方法
     * @param resultEnum 返回枚举
     * @param data 具体返回对象
     * @return ResponseWrapper封装类
     */
    public static ResponseWrapper markCustom(ResultEnum resultEnum, Object data){
        ResponseWrapper responseWrapper = new ResponseWrapper();
        responseWrapper.setCode(resultEnum.getCode());
        responseWrapper.setMessage(resultEnum.getMessage());
        responseWrapper.setData(data);
        return responseWrapper;
    }

    /**
     * 用户自定义结果
     * @param code 编码
     * @param message 信息
     * @param data 数据
     * @return ResponseWrapper
     */
    public static ResponseWrapper markCustom(Integer code, String message, Object data){
        ResponseWrapper responseWrapper = new ResponseWrapper();
        responseWrapper.setCode(code);
        responseWrapper.setMessage(message);
        responseWrapper.setData(data);
        return responseWrapper;
    }

    /**
     * 用户自定义结果
     * @param message 信息
     * @param data 数据
     * @return ResponseWrapper
     */
    public static ResponseWrapper markCustomSuccess(String message, Object data){
        ResponseWrapper responseWrapper = new ResponseWrapper();
        responseWrapper.setCode(10000);
        responseWrapper.setMessage(message);
        responseWrapper.setData(data);
        return responseWrapper;
    }

    /**
     * 用户自定义结果
     * @param message 信息
     * @return ResponseWrapper
     */
    public static ResponseWrapper markCustomSuccess(String message){
        ResponseWrapper responseWrapper = new ResponseWrapper();
        responseWrapper.setCode(10000);
        responseWrapper.setMessage(message);
        return responseWrapper;
    }

    /**
     * 用户自定义结果
     * @param message 信息
     * @return ResponseWrapper
     */
    public static ResponseWrapper markCustomError(String message){
        ResponseWrapper responseWrapper = new ResponseWrapper();
        responseWrapper.setCode(10001);
        responseWrapper.setMessage(message);
        return responseWrapper;
    }


    /**
     * 自定义返回结果【错误时】只需要传输错误码和消息
     * @param resultEnum 枚举信息
     * @return ResponseWrapper封装类
     */
    public static ResponseWrapper markCustom(ResultEnum resultEnum){
        ResponseWrapper responseWrapper = new ResponseWrapper();
        responseWrapper.setCode(resultEnum.getCode());
        responseWrapper.setMessage(resultEnum.getMessage());
        responseWrapper.setData(null);
        return responseWrapper;
    }

    /**
     * 自定义返回结果【业务错误】只需要传输错误码和消息
     * @param businessException 枚举信息
     * @return ResponseWrapper封装类
     */
    public static ResponseWrapper markCustom(BusinessException businessException){
        ResponseWrapper responseWrapper = new ResponseWrapper();
        responseWrapper.setCode(businessException.getCode());
        responseWrapper.setMessage(businessException.getMessage());
        responseWrapper.setData(null);
        return responseWrapper;
    }


    /**
     * 返回错误
     * @return ResponseWrapper封装类
     */
    public static ResponseWrapper markError() {
        ResponseWrapper responseWrapper = new ResponseWrapper();
        responseWrapper.setCode(ResultEnum.FAILED.getCode());
        responseWrapper.setMessage(ResultEnum.FAILED.getMessage());
        return responseWrapper;
    }

    /**
     * 自定义返回错误信息
     * @param resultEnum 返回枚举
     * @return 错误信息
     */
    public static ResponseWrapper markError(ResultEnum resultEnum) {
        ResponseWrapper responseWrapper = new ResponseWrapper();
        responseWrapper.setCode(resultEnum.getCode());
        responseWrapper.setMessage(resultEnum.getMessage());
        return responseWrapper;
    }

    /**
     * 自定义返回错误信息
     * @param resultEnum 返回枚举
     * @param object 错误对象
     * @return 错误信息
     */
    public static ResponseWrapper markError(ResultEnum resultEnum, Object object) {
        ResponseWrapper responseWrapper = new ResponseWrapper();
        responseWrapper.setCode(resultEnum.getCode());
        responseWrapper.setMessage(resultEnum.getMessage());
        responseWrapper.setData(object);
        return responseWrapper;
    }


    /**
     * 查询成功且有数据
     * @param data 需要返回的对象
     * @return ResponseWrapper封装类
     */
    public static ResponseWrapper markSuccess(Object data) {
        ResponseWrapper responseWrapper = new ResponseWrapper();
        responseWrapper.setCode(ResultEnum.SUCCESS.getCode());
        responseWrapper.setMessage(ResultEnum.SUCCESS.getMessage());
        responseWrapper.setData(data);
        return responseWrapper;
    }

    /**
     * 查询成功无数据
     * @return ResponseWrapper封装类
     */
    public static ResponseWrapper markSuccess() {
        ResponseWrapper responseWrapper = new ResponseWrapper();
        responseWrapper.setCode(ResultEnum.SUCCESS.getCode());
        responseWrapper.setMessage(ResultEnum.SUCCESS.getMessage());
        responseWrapper.setData(null);
        return responseWrapper;
    }
}
